This is the lower reach of the larger turbulent mountain stream, Blackwood Creek in CA, USA.
We then ran the normal stream metabolizer model:
b_Kb_oipi_tr_plrckm.stan to get modeled K600 to see if we
could resolve the negative correlation between ER and K600. Priors on
K600_lnQ_nodes_meanlog were set as 5 bins based on
rnorm(1000, mean = logQ_mean, sd = logQ_sd) centered around
the mean and logQ values 1-2 sd away from the mean.
We chose segments of time where we believe GPP occurred and was greater than 0. These chunks of time are from a previous model where we binned flow and incorporated measured and estimated K600 priors from gas exchange measurements a the reach.
This the raw model output. It looks okay aside from some small parts of 2023. Where GPP is in blue and ER is in orange, and the black points represent NEP.
Here is the run configuration for full model:
mm_name(type = 'bayes', pool_K600 = "binned", err_obs_iid = TRUE, err_proc_iid = TRUE, ode_method = "trapezoid", deficit_src = 'DO_mod', engine = 'stan')
Fitting priors:
K600_lnQ_nodes_meanlog = log(22) Where 16 was the mean
value from observed measurements and normal pooled modeled,
K600_lnQ_nodes_sdlog = 1.04
bayes_specs_new$K600_lnQ_nodes_centers <- log_bins was
from
prior_samples <- rnorm(1000, mean = logQ_mean, sd = logQ_sd)
Make sure the chains converged; all r-hat values were well below 1.05 (the red line) for GPP, ER, and K600. The blue lines are the mean for each parameter.
** Some poor convergence in 2023 for K600
Looks like that weird 2023 time period corresponds to bad rhats for all parameters.
## [1] 1.010588
## [1] 1.002292
## [1] 1.006689
## date lab rmse sd
## Min. :2021-04-29 Length:1660 Min. :0.0115 Min. :0.009324
## 1st Qu.:2022-01-23 Class :character 1st Qu.:0.0469 1st Qu.:0.287383
## Median :2022-09-18 Mode :character Median :0.0708 Median :0.422103
## Mean :2022-12-01 Mean :0.0972 Mean :0.402806
## 3rd Qu.:2023-10-22 3rd Qu.:0.1359 3rd Qu.:0.514854
## Max. :2024-08-16 Max. :0.5736 Max. :0.991350
## NA's :322
## min max range nrmse
## Min. : 5.309 Min. : 7.071 Min. :0.02967 Min. :0.0108
## 1st Qu.: 6.891 1st Qu.: 8.398 1st Qu.:0.90400 1st Qu.:0.0407
## Median : 7.926 Median : 9.306 Median :1.33250 Median :0.0602
## Mean : 7.998 Mean : 9.272 Mean :1.27435 Mean :0.0709
## 3rd Qu.: 9.051 3rd Qu.:10.228 3rd Qu.:1.57733 3rd Qu.:0.0916
## Max. :10.576 Max. :11.698 Max. :3.85600 Max. :0.2196
## NA's :322
## minT maxT rangeT
## Min. : 1.003 Min. : 1.134 Min. : 0.06267
## 1st Qu.: 1.982 1st Qu.: 6.837 1st Qu.: 3.93300
## Median : 5.455 Median :12.025 Median : 6.25483
## Mean : 6.362 Mean :12.344 Mean : 5.98229
## 3rd Qu.:10.149 3rd Qu.:17.882 3rd Qu.: 8.21533
## Max. :16.889 Max. :26.203 Max. :11.01667
##
Here is the run configuration:
bayes_specs_new
bayes_name_new <- mm_name(type = 'bayes', pool_K600 = "normal", err_obs_iid = TRUE, err_proc_iid = TRUE, ode_method = "trapezoid", deficit_src = 'DO_mod', engine = 'stan')
Where each “lab” segment was run as individual model with the
K600_lnQ_nodes_meanlog adjusted to match streamline in cms
during that time.
There is a strong negative correlation between ER and K600 (-0.96). GPP and K600 are slightly less correlated (0.288).
met.clean <- met.df %>%
filter(GPP_daily_Rhat<1.1)%>%
filter(GPP_97.5pct>0)%>%
filter(ER_daily_Rhat<1.1) %>%
filter(ER_2.5pct<0)%>%
filter(K600_daily_Rhat<1.1)
mean_k_mod <- mean(met.clean$K600_daily_mean)
mean_k_mod## [1] 21.11758
## [1] 22.96813
## [1] -0.863
## [1] 0.185
Plots for (1) measured v modeled K600 and flow and (2) logK600 and log(flow+1).
Could be one poor measurement at the highest flow for measured gas
exchange. But in general the modeled K600 does seem similar to the
measured, which is kind of nice to see how robust the
pool_K600 = "normal" is getting at K600.
## [1] 21.11758
## [1] 22.96813
k.q <- met.clean %>%
left_join(mod.env.ag, by = "date") %>%
full_join(measured_K, by = c("date", "source",
"K600_daily_mean"= "K600",
"discharge"= "Q_cms")) %>%
ggplot(aes(x = discharge, y = K600_daily_mean, col = source, shape=source))+
geom_point( size = 2) +
theme_bw()+
#scale_x_log10(limits = c(20, 800))+
scale_color_viridis_d(option = "viridis")
k.q_log <- met.clean %>%
left_join(mod.env.ag, by = "date") %>%
full_join(measured_K, by = c("date", "source",
"K600_daily_mean"= "K600",
"discharge"= "Q_cms")) %>%
ggplot(aes(x = log(discharge+1), y = log(K600_daily_mean), col = source, shape=source))+
geom_point( size = 2) +
theme_bw()+
#scale_x_log10(limits = c(20, 800))+
scale_color_viridis_d(option = "viridis")
plot_grid(k.q, k.q_log, ncol = 2)## [1] 22.04286
Here is the run configuration for full model:
mm_name(type = 'bayes', pool_K600 = "binned", err_obs_iid = TRUE, err_proc_iid = TRUE, ode_method = "trapezoid", deficit_src = 'DO_mod', engine = 'stan')
Where dashed vertical lines correspond to the prior locations for
flow bins in
bayes_specs_new$K600_lnQ_nodes_centers <- log_bins
Plots made on filtered data: met.clean
filtered for days with
GPP_daily_Rhat<1.05,ER_daily_Rhat<1.05,
K600_daily_Rhat <1.05, as well as
(GPP_97.5pct>0) and (ER_2.5pct<0).
met.clean <- met.full %>%
filter(GPP_daily_Rhat<1.05)%>%
filter(GPP_97.5pct>0)%>%
filter(ER_daily_Rhat<1.05) %>%
filter(ER_2.5pct<0)%>%
filter(K600_daily_Rhat<1.05)
mean_k_mod <- mean(met.clean$K600_daily_mean)
mean_k_mod## [1] 22.39667
## [1] 22.96813
KER_cor <- round(cor(met.clean$ER_daily_mean, met.clean$K600_daily_mean, use = "complete.obs"),3)
print(KER_cor)## [1] -0.543
KGPP_cor <-round(cor(met.clean$GPP_daily_mean, met.clean$K600_daily_mean, use = "complete.obs"),3)
print(KGPP_cor)## [1] -0.003
The vertical dashed is the overall mean modeled K600 in the box plot.
## [1] -0.704
The direction of the K600 ~ flow relationship looks more logical, where K600 increases with flow. ER and K600 are negatively correlated (-0.543), GPP and K600 are negatively correlated (-0.003). but, less strongly relative to the lower reach (GBL). The relationship between K600 and flow appears to be positive but still inflected in a strange way.
However I’m still think we should be cautious in over interpreting ER trends.
The mean modeled K600 and measured gas exchange are essentially the same 22.
Where GPP is in blue and ER is in orange, and the black points represent NEP.
Of the 878 days with DO observations 385 days were removed.
| Number of Days | Explaination | Percent of Days |
|---|---|---|
| 878 | Total days of DO observations | 100.0 |
| 385 | Total days removed | 43.8 |
| 209 | Days model was unable to fit | 23.8 |
| 0 | days where GPP rhat > 1.05 | 0.0 |
| 0 | days where ER rhat > 1.05 | 0.0 |
| 0 | days where K600 rhat > 1.05 | 0.0 |
| 176 | days where modeled GPP was negative | 20.0 |
| 2 | days where modeled ER was positive | 0.2 |
R version 4.4.2 (2024-10-31)
Platform: aarch64-apple-darwin20
locale: en_US.UTF-8||en_US.UTF-8||en_US.UTF-8||C||en_US.UTF-8||en_US.UTF-8
attached base packages: stats, graphics, grDevices, utils, datasets, methods and base
other attached packages: plotly(v.4.10.4), kableExtra(v.1.4.0), knitr(v.1.49), streamMetabolizer(v.0.12.1), ggpubr(v.0.6.0), readxl(v.1.4.3), zoo(v.1.8-12), cowplot(v.1.1.3), viridis(v.0.6.5), viridisLite(v.0.4.2), dataRetrieval(v.2.7.17), lubridate(v.1.9.4), forcats(v.1.0.0), stringr(v.1.5.1), dplyr(v.1.1.4), purrr(v.1.0.2), readr(v.2.1.5), tidyr(v.1.3.1), tibble(v.3.2.1), ggplot2(v.3.5.1) and tidyverse(v.2.0.0)
loaded via a namespace (and not attached): DBI(v.1.2.3), gridExtra(v.2.3), rlang(v.1.1.4), magrittr(v.2.0.3), e1071(v.1.7-16), compiler(v.4.4.2), mgcv(v.1.9-1), systemfonts(v.1.1.0), vctrs(v.0.6.5), pkgconfig(v.2.0.3), crayon(v.1.5.3), fastmap(v.1.2.0), backports(v.1.5.0), labeling(v.0.4.3), pander(v.0.6.5), deSolve(v.1.40), rmarkdown(v.2.29), tzdb(v.0.4.0), bit(v.4.5.0.1), xfun(v.0.49), cachem(v.1.1.0), jsonlite(v.1.8.9), broom(v.1.0.7), parallel(v.4.4.2), R6(v.2.5.1), bslib(v.0.8.0), stringi(v.1.8.4), car(v.3.1-3), jquerylib(v.0.1.4), cellranger(v.1.1.0), Rcpp(v.1.0.14), Matrix(v.1.7-1), splines(v.4.4.2), timechange(v.0.3.0), tidyselect(v.1.2.1), rstudioapi(v.0.17.1), abind(v.1.4-8), yaml(v.2.3.10), lattice(v.0.22-6), plyr(v.1.8.9), withr(v.3.0.2), evaluate(v.1.0.1), rLakeAnalyzer(v.1.11.4.1), sf(v.1.0-19), units(v.0.8-5), proxy(v.0.4-27), xml2(v.1.3.6), pillar(v.1.10.1), carData(v.3.0-5), KernSmooth(v.2.23-24), generics(v.0.1.3), vroom(v.1.6.5), hms(v.1.1.3), munsell(v.0.5.1), scales(v.1.3.0), class(v.7.3-22), glue(v.1.8.0), lazyeval(v.0.2.2), tools(v.4.4.2), data.table(v.1.16.4), ggsignif(v.0.6.4), LakeMetabolizer(v.1.5.5), grid(v.4.4.2), crosstalk(v.1.2.1), colorspace(v.2.1-1), nlme(v.3.1-166), Formula(v.1.2-5), cli(v.3.6.3), svglite(v.2.1.3), gtable(v.0.3.6), rstatix(v.0.7.2), sass(v.0.4.9), digest(v.0.6.37), classInt(v.0.4-11), htmlwidgets(v.1.6.4), farver(v.2.1.2), htmltools(v.0.5.8.1), lifecycle(v.1.0.4), httr(v.1.4.7), unitted(v.0.2.9) and bit64(v.4.5.2)